/* eslint-disable no-restricted-globals */
/* eslint-disable no-shadow */
/* eslint-disable no-unused-vars */
import { defineStore } from 'pinia';

export enum ModeEnum {
  DEV = 'DEV',
  PROD = 'PROD',
}

interface State {
  env: string;
  nodeEnv: string;
  current: ModeEnum;
}
const getCurrent = () => {
  if (import.meta.env.MODE === 'development' || location.hostname.includes('uat-')) {
    return localStorage.getItem('mode') ? localStorage.getItem('mode') : ModeEnum.DEV;
  }
  return ModeEnum.PROD;
};
let env = 'prod';
if (location.hostname.startsWith('local')) env = 'uat';
if (location.hostname.startsWith('uat-')) env = 'uat';
if (location.hostname.startsWith('pre-')) env = 'pre';
const initState = {
  env,
  nodeEnv: (import.meta.env.MODE === 'development' || (location.hostname.includes('uat-')) ? 'development' : 'production'),
  current: getCurrent(),
};
const useModeStore = defineStore('mode', {
  state: () => (initState as State),
  actions: {
    setMode(e: ModeEnum) {
      localStorage.setItem('mode', e);
      this.current = e;
    },
  },
});

export default useModeStore;
